import {ref} from 'vue';

export function useCitySelect() {
    const fromCity = ref("北京");
    const toCity = ref("上海");
    const showCitySelect = ref(false);
    const currentSelectType = ref("");

    const showCityPicker = (type) => {
        currentSelectType.value = type;
        showCitySelect.value = true;
    };

    const selectCity = (city) => {
        if (currentSelectType.value === "from") {
            fromCity.value = city.name;
        } else {
            toCity.value = city.name;
        }
        showCitySelect.value = false;
    };

    const exchangeCity = () => {
        [fromCity.value, toCity.value] = [toCity.value, fromCity.value];
    };

    return {
        fromCity,
        toCity,
        showCitySelect,
        currentSelectType,
        showCityPicker,
        selectCity,
        exchangeCity,
    };
}